package com.liuliu.controller.zua;

import com.liuliu.common.annotation.Log;
import com.liuliu.common.core.controller.BaseController;
import com.liuliu.common.core.domain.AjaxResult;
import com.liuliu.common.core.domain.model.LoginUser;
import com.liuliu.common.core.page.TableDataInfo;
import com.liuliu.common.enums.BusinessType;
import com.liuliu.common.utils.ServletUtils;
import com.liuliu.common.utils.poi.ExcelUtil;
import com.liuliu.framework.web.service.TokenService;
import com.liuliu.zua.domain.ZuaCourse;
import com.liuliu.zua.service.IZuaCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * courseController
 * 
 * @author liuliu
 * @date 2021-03-22
 */
@RestController
@RequestMapping("/zua/course")
public class ZuaCourseController extends BaseController
{

    @Autowired
    private IZuaCourseService zuaCourseService;

    /**
     * 查询course列表
     */
    @PreAuthorize("@ss.hasPermi('zua:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZuaCourse zuaCourse)
    {
        startPage();
        List<ZuaCourse> list = zuaCourseService.selectZuaCourseList(zuaCourse);
        return getDataTable(list);
    }

    /**
     * 导出course列表
     */
    @PreAuthorize("@ss.hasPermi('zua:course:export')")
    @Log(title = "course", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZuaCourse zuaCourse)
    {
        List<ZuaCourse> list = zuaCourseService.selectZuaCourseList(zuaCourse);
        ExcelUtil<ZuaCourse> util = new ExcelUtil<ZuaCourse>(ZuaCourse.class);
        return util.exportExcel(list, "course");
    }

    /**
     * 获取course详细信息
     */
    @PreAuthorize("@ss.hasPermi('zua:course:query')")
    @GetMapping(value = "/{courseId}")
    public AjaxResult getInfo(@PathVariable("courseId") Long courseId)
    {
        return AjaxResult.success(zuaCourseService.selectZuaCourseById(courseId));
    }

    /**
     * 新增course
     */
    @PreAuthorize("@ss.hasPermi('zua:course:add')")
    @Log(title = "course", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZuaCourse zuaCourse)
    {
        return toAjax(zuaCourseService.insertZuaCourse(zuaCourse));
    }

    /**
     * 修改course
     */
    @PreAuthorize("@ss.hasPermi('zua:course:edit')")
    @Log(title = "course", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZuaCourse zuaCourse)
    {
        return toAjax(zuaCourseService.updateZuaCourse(zuaCourse));
    }

    /**
     * 删除course
     */
    @PreAuthorize("@ss.hasPermi('zua:course:remove')")
    @Log(title = "course", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseIds}")
    public AjaxResult remove(@PathVariable Long[] courseIds)
    {
        return toAjax(zuaCourseService.deleteZuaCourseByIds(courseIds));
    }
    /**
     * 查询course列表
     */

    @GetMapping("/listByStudenId/{studentId}")
    public TableDataInfo listByStudenId(ZuaCourse zuaCourse,@PathVariable("studentId")Integer studentId)
    {
        startPage();
        zuaCourse.setCourseId(Long.valueOf(studentId));
        List<ZuaCourse> list = zuaCourseService.selectZuaCourseListByStudentId(zuaCourse);
        return getDataTable(list);
    }

}
